﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.BusinessLogicLayer;
public partial class SchoolManagement_SearchAndDeleteSchool : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
 
        }

    }
    public void Bind()
    {

        SchoolModule sm = new SchoolModule();
        DataSet ds = new DataSet();
        if (this.SchoolID == 0)
        { ds = sm.QueryAllSchool(); }
        else { ds = sm.GetSchoolListByWhere(" and ID=" + this.SchoolID); Button1.Visible = false; }
        rptCoursewareList.DataSource = getPage(ds);
        rptCoursewareList.DataBind();
    }

    
    protected void Seacher_Click(object sender, EventArgs e)
    {
        if (TxtCheckName.Text.Trim() == null || TxtCheckName.Text.Trim() == "")
        { Bind(); }
        else
        {
            CheckBind(TxtCheckName.Text.Trim());
         }
    }
    public void CheckBind(string name)
    {
       SchoolModule sm = new SchoolModule();
        string where = "";
        if (this.SchoolID == 0)
        { where = "  and  VS_name like '%" + name + "%'"; }

        else { where = " and ID=" + this.SchoolID + "  and  VS_name like '%" + name + "%'"; }
        DataSet da = sm.GetSchoolListByWhere(where);
        rptCoursewareList.DataSource = getPage(da);
        rptCoursewareList.DataBind(); 
      
    }
    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        if (TxtCheckName.Text.Trim() == null || TxtCheckName.Text.Trim() == "")
        { Bind(); }
        else
        {
            CheckBind(TxtCheckName.Text.Trim());
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("RegisterSchoolInfo.aspx");
    }
    public void btnUpdate_Click(object sender, CommandEventArgs e)
    {
        Response.Redirect("UpdateSchoolInfo.aspx?SID=" + e.CommandArgument.ToString());
    }

}
